<script type="text/javascript" id="pageScript" src="/external/js/pagination.js?formId=question-form"></script>

<div class="container">
	<?php
	if(isset($message) && $message){
		echo '<div class="alert alert-success">'.$message.'</div>';
	}
	?>

	<form id="question-form" name="question-form" action="<?=site_url('admin/question/list')?>" method="post">
		<h2>Question List</h2>
		<input type="hidden" name="id"/>
		<div class="row">
			<div class="form-group col-md-6">
				<label>Section</label>
				<select class="form-control" id="section" name="q_section">
		    		<option></option>
		    		<?if(isset($search['q_version'])){?>
						<option value='Section1' <?=$search['q_section']=='Section1'?'selected':''?>>Section1</option>
						<option value='Section2' <?=$search['q_section']=='Section2'?'selected':''?>>Section2</option>
						<option value='Section3' <?=$search['q_section']=='Section3'?'selected':''?>>Section3</option>
						<option value='Section4' <?=$search['q_section']=='Section4'?'selected':''?>>Section4</option>
		    		<?}else{?>
		    			<option value='Section1'>Section1</option>
						<option value='Section2'>Section2</option>
						<option value='Section3'>Section3</option>
						<option value='Section4'>Section4</option>
		    		<?}?>
		    	</select>
			</div>
			<div class="form-group col-md-6">
				<label>Aswers</label>
				<input class="form-control" name="q_answer_str" value="<?php echo isset($search['q_answer_str'])?$search['q_answer_str']:''; ?>">
			</div>
		</div>
		<div class="form-actions">
			<button type="submit" class="btn btn-primary">Search</button>
			<button type="button" class="btn btn-default" onclick="location.href='/index.php/admin/question/add'">Add</button>
		</div>
		<input type="hidden" name="sort" id="sort" value="<?=(isset($search['sort'])?$search['sort']:'')?>"/>
		<input type="hidden" name="desc" id="desc" value="<?=(isset($search['desc'])?$search['desc']:'')?>"/>
	</form>

	<div class="module mod-line-top">
		<table class="table table-striped table-hover">
			<thead>
			  	<tr>
				    <!--<th>#</th>-->
				    <th><a class="sort" id="id">ID<a/></th>
				    <th><a class="sort" id="title">Title<a/></th>
				    <th><a class="sort" id="section">Section<a/></th>
				    <th>Operation</th>
			  	</tr>
			</thead>
			<tbody>
				<?php $index = $this->uri->segment(3);
				?>
				<?php foreach ($results as $item): $offset++;?>
				<tr>
				    <!--<td><a href="/index.php/admin/question/edit/<?=$item['id']?>"><?=$offset?></a></td>-->
				    <td><a href="/index.php/question/preview/<?=$item['id']?>" class="timu-preview"><?=$item['id']?></a></td>
				    <td><a href="/index.php/question/preview/<?=$item['id']?>" class="timu-preview"><?=$item['title']?></a></td>
				    <td><a href="/index.php/question/preview/<?=$item['id']?>" class="timu-preview"><?=$item['section']?></a></td>
				    <td>
				    	<button type="button" class="btn btn-primary timu-edit" id="<?=$item['id']?>">Edit</button>
				      	<button type="button" class="btn btn-primary timu-delete" id="<?=$item['id']?>">Delete</button>
      				</td>
			  	</tr>
				<?php endforeach ?>
			  	
			</tbody>
		</table>
		
		<?=$this->pagination->create_links();?>
	</div>
</div>

<script>
$(document).ready(function() {
	$(".timu-edit").each(function(){
		var btn = $(this);
	    btn.click(function(){location.href = '/index.php/admin/question/edit/' + btn.attr('id');})
	});
	
	
	$(".timu-delete").each(function(){
	   var btn = $(this);
	    btn.click(function(){
	    	$('#question-form').attr('action', '/index.php/admin/question/delete/' + btn.attr('id'));
	    	$('#question-form').submit();
	    })
	});
	
	
	$(".timu-preview").each(function(){
		$(this).fancybox({
			'width'				: '70%',
			'height'			: '75%',
	        'autoScale'     	: false,
	        'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	
	})
	
});
</script>
